import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rwini_edit/config/config.dart';
import 'package:rwini_edit/view/home/lbox.dart';
import 'package:rwini_edit/view/home/logic.dart';
import 'package:rwini_edit/view/home/rbox.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    final logic = Get.put(HomeLogic());

    return Scaffold(
      appBar: AppBar(
          centerTitle: true,
          title: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                children: [
                  Text("字体大小：${conf.fontsise}"),
                  Slider(
                    value: conf.fontsise,
                    min: 10,
                    max: 80,
                    divisions: 16,
                    onChanged: (double v) {
                      setState(() {
                        conf.fontsise = v.toInt().toDouble();
                        print(v);
                      });
                    },
                  ),
                  TextButton(
                    onPressed: () {
                      setState(() {
                        conf.fontsise = 22;
                      });
                    },
                    child: const Text("重置"),
                  )
                ],
              ),
              Expanded(child: Container()),
              const Text("铁锈Mod编辑器"),
              Expanded(child: Container()),
              IconButton(
                onPressed: () {
                  showDialog(
                    context: context,
                    builder: (ctx) => AboutDialog(
                      applicationName: "铁锈战争mod文件编辑器",
                      applicationVersion: "Bate测试版",
                      applicationIcon: const FlutterLogo(),
                      applicationLegalese: "Copyright@ 2024 番茄是水果",
                    ),
                  );
                },
                icon: Icon(
                  Icons.help,
                  size: conf.fontsise,
                ),
              ),
            ],
          )),
      body: _buildBody(logic),
    );
  }

  Widget _buildBody(HomeLogic logic) => Row(
        children: [
          Expanded(flex: conf.bili.first, child: buildLBox(logic)),
          Expanded(flex: conf.bili.last, child: buildRBox(logic)),
        ],
      );
}

// class MyHomePage extends StatelessWidget {
//   const MyHomePage({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     final logic = Get.put(HomeLogic());
//
//     return Scaffold(
//       appBar: AppBar(
//           centerTitle: true,
//           title: Row(
//             crossAxisAlignment: CrossAxisAlignment.center,
//             children: [
//               Slider(
//                 value: conf.fontsise,
//                 min: 10,
//                 max: 100,
//                 onChanged: (v) {
//                   print(v);
//                 },
//               ),
//               // IconButton(
//               //   onPressed: () async {
//               //     var res = await getdialogSetting();
//               //   },
//               //   icon: Icon(
//               //     Icons.settings_applications,
//               //     size: conf.fontsise,
//               //   ),
//               // ),
//               Expanded(child: Container()),
//               const Text("铁锈Mod编辑器"),
//               Expanded(child: Container()),
//               IconButton(
//                 onPressed: () {
//                   showDialog(
//                     context: context,
//                     builder: (ctx) => AboutDialog(
//                       applicationName: "铁锈战争mod文件编辑器",
//                       applicationVersion: "Bate测试版",
//                       applicationIcon: const FlutterLogo(),
//                       applicationLegalese: "Copyright@ 2024 番茄是水果",
//                     ),
//                   );
//                 },
//                 icon: Icon(
//                   Icons.help,
//                   size: conf.fontsise,
//                 ),
//               ),
//             ],
//           )),
//       body: _buildBody(logic),
//     );
//   }
//
//   Widget _buildBody(HomeLogic logic) => Row(
//         children: [
//           Expanded(flex: conf.bili.first, child: buildLBox(logic)),
//           Expanded(flex: conf.bili.last, child: buildRBox(logic)),
//         ],
//       );
// }
